<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" 
	import="java.util.*,my_web.bean.*,my_web.page.*"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  	//request是jsp的内置对象，无需定义和创建，系统会自动定义和创建，直接使用即可
	Page pg=(Page)request.getAttribute("pg");
	List<Dep>list=(List<Dep>)pg.getReclist();
--%> 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>部门列表</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid" style="padding-left:2px;padding-right:2px;">
	<ol class="breadcrumb" style="margin-bottom:5px;">
	  <li><a href="#">基础信息</a></li>
	  <li class="active">部门信息</li>
	</ol>
<form action="DepDoMultiDel.do" method="post" name="fenye">
	<div class="panel panel-default" style="padding:5px;">
				<a class="btn btn-default" href="DepToAdd.do"><span class="glyphicon glyphicon-plus" ></span> 新增</a>
		  		<button type="submit" class="btn btn-default" id="bt1" ><span class="glyphicon glyphicon-trash" ></span> 删除</button>
		  		 部门编号：<input type="text" name="d_id" value="${param.d_id}" size=5/>
				部门名称：<input type="text" name="d_name" value="${param.d_name}" size=5/>
				 部门备注：<input type="text" name="d_state" value="${param.d_state}" size=5/>
				<input type="submit" value="查询" formaction="DepToList.do" size=5/>
	 </div>
  <table class="table table-bordered" >
  	<thead>
	  	<tr>
	  		<th>选择</th>
	  		<th>部门编号</th>
	  		<th>部门名称</th>
	  		<th>部门备注</th>
	  		<th>操作</th>
	  	</tr>
  	</thead>
  	<tbody>
		  	<%-- <% //jsp脚本
		  		for(Dep dep:list){
		  	%> --%>
		  	<c:forEach items="${pg.reclist}" var="dep">
	  		<tr>
		  		     <td>
		  		     	<input type="checkbox" name="d_ids" value="${dep.d_id }"/>
		  		     </td>
			  		 <td>${dep.d_id }</td><%--out是jsp的内置对象，负责向浏览器输出信息的字符流 --%>
			  		 <td>${dep.d_name }</td><%--jsp表达式 --%>
			  		 <td>${dep.d_state }</td> <%--jsp表达式 --%>
			  		 <td>
				  		 <a href="DepDoDel.do?d_id=${dep.d_id }" class="del">删除</a>
				  		 <a href="DepToUpd.do?d_id=${dep.d_id }" >修改</a>
			  		 </td>
	  		</tr>
	  		</c:forEach>
	  		<%-- <%
		  		}
	  		%> --%>
  	</tbody>
  </table>
  </form>
  <nav>
		<ul class="pager">
			<li>
				<a href="" onclick="document.fenye.action='DepToList.do?page=${pg.first}';document.fenye.submit();return false;">首页</a>
			</li>
			<li>
				<a href="" onclick="document.fenye.action='DepToList.do?page=${pg.prior}';document.fenye.submit();return false;">上一页</a>
			</li>
			<li>
				<a href="" onclick="document.fenye.action='DepToList.do?page=${pg.next}';document.fenye.submit();return false;">下一页</a>
			</li>
			<li>
				<a href="" onclick="document.fenye.action='DepToList.do?page=${pg.last}';document.fenye.submit();return false;">尾页</a>
			</li>
			<li>
				第${pg.curr}页 共${pg.pgTotal}页 共${pg.total}条记录
			</li>
			<li><form action="DepToList.do" style="display: inline-block;">跳转至
				<input type="text"  name="page" style="width:25px;" value="">页
	 				<button type="submit">GO</button> </form>
	    	</li>
	    </ul>
	</nav>
 </div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-3.3.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>

<script type="text/javascript">
	var del_links=document.querySelectorAll(".del");
	for(var i=0;i<del_links.length;i++){
		del_links[i].onclick=function(){
			if(confirm("您确实要删除该条数据吗？")){
				var xhr=new XMLHttpRequest();
				var url=this.href;
				xhr.open('get', url, true);
				xhr.onreadystatechange=function(){
					if(this.readyState==4){
						var jsonStr=this.responseText;
						//eval('var result='+jsonStr);
						var result=eval("("+jsonStr+")");
						//var result={"success":true,"msg":"删除成功！"};
						if(this.status==200){
							if(result.success){
								alert(result.msg);
								window.location.href='DepToList.do';
							}else{
								alert(result.msg);
							}
						}else{
							alert("请求地址不正确或者服务器出错！");
						}
					}
				};
				xhr.send();
			}
			return false;
		};
	}
</script>
<script type="text/javascript">
	document.getElementById("bt1").onclick=function(){
		return confirm("你真的要删除该部门信息吗？想好了哦！");
	}
</script>
</body>
</html>